from selenium import webdriver
from selenium.webdriver.common.by import By
import  time
service=webdriver.ChromeService(executable_path='./chromedriver-win64/chromedriver.exe')
options = webdriver.ChromeOptions()
options.add_experimental_option('detach', True)
browser = webdriver.Chrome(options=options, service=service)
browser.get("https://www.baidu.com")
time.sleep(2)
input = browser.find_element(by=By.ID, value='kw')
input.send_keys('周杰伦')
#获取按钮
time.sleep(2)
button =browser.find_element(by=By.ID, value='su')
button.click()
browser.execute_script('document.documentElement.scrollTop=10000')
#获取下一页

# # 获取当前所有窗口句柄
# handles = browser.window_handles
#
# # 切换到最新窗口
# browser.switch_to.window(handles[-1])

time.sleep(2)
#bs4
next_page = browser.find_element(by=By.CSS_SELECTOR,value='.n')
#next_page=browser.find_element(by=By.XPATH,value='//a[@class="n"]')
next_page.click()


#回到上一页
time.sleep(2)
browser.back()

#退回
time.sleep(3)
browser.forward()
time.sleep(4)
browser.quit()
